<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@ taglib prefix="form" uri="http://www.springframework.org/tags/form" %>
<%@ taglib prefix="tag" uri="http://www.springframework.org/tags" %>
<%@ taglib prefix="ct" uri="http://java.sun.com/jsp/jstl/core" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<link rel="stylesheet" type="text/css" href="<%= request.getContextPath() %>/views/includes/css/style.css" />
<title>Manage - Post feed</title>
</head>
<body>
    <div id="wrapper">
    <jsp:include page="../includes/loginFB.jsp">
        <jsp:param name="perms" value="read_stream,publish_stream,offline_access,email,manage_pages"/>
    </jsp:include>
        
    <div id="app-title"><h1>Ad-campaign-facebook application</h1></div>
    <%@ include file="../includes/navigation.jsp" %>
    
    <div id='fb-root'></div>
    <script src='http://connect.facebook.net/en_US/all.js'></script>
    <div id="feed-wrapper" style="display: inline-block;">
    	<ul>
    	<ct:forEach items="${photos}" var="photo">
    		<li style="overflow: auto; border: 1px solid #333">
	    		<div style="float:left;"><img src="<ct:out value="${photo.url}"/>"/></div>
	    		<div style="margin-top: 100px; font-size: medium; font-weight: bold;"><ct:out value="${photo.title}"/></div>
    		</li>
    	</ct:forEach>
    	</ul>
    </div>
    <input type="submit" onclick="postToFeed();return false;"/>
    <script>     

        function postToFeed() {
            	var photoList = ${jsonPhotos};
            	for(var i = 0 ; i < photoList.length ; i++){
                var txt = photoList[i].title;
                var hyperlink = photoList[i].url;
                var image = photoList[i].url;
                FB.api('/me/feed', 'post', { message: txt, link: hyperlink, picture: image}, function(response) {
                  if (!response || response.error) {
                    alert('Wystąpił błąd');
                  } else {
                    //alert('Dodano treść o ID: ' + response.id);
                  }
                });
            	}
                alert("Dodano do serwisów");
      }
     
    
    </script>
 </div>
</body>
</html>